package com.shenzhen.horselive.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebHistoryItem;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.shenzhen.horselive.R;
import com.shenzhen.horselive.beans.MyCityBean;
import com.shenzhen.horselive.beans.PayWayBean;
import com.shenzhen.horselive.databinding.DialogPayWaysBinding;
import com.shenzhen.horselive.utils.DialogManager;

import java.util.ArrayList;
import java.util.List;

public class DialogPayways extends Dialog {
    public DialogPayways(@NonNull Context context) {
        super(context, R.style.CommonDialog);
        initViews();
    }

    public DialogPayways(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected DialogPayways(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    private  OnButtonClick  onButtonClick;

    public void setOnButtonClick(OnButtonClick onButtonClick) {
        this.onButtonClick = onButtonClick;
    }

    DialogPayWaysBinding  binding;
    int  type ;  //0是微信   1是支付宝
    private void initViews() {
        binding =  DialogPayWaysBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.containerWeixin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                type=0;
                binding.imgCheck.setImageResource(R.mipmap.ico_checked);
                binding.imgCheckAli.setImageResource(R.mipmap.ico_un_check);

            }
        });
        binding.containerAli.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                type=1;
                binding.imgCheck.setImageResource(R.mipmap.ico_un_check);
                binding.imgCheckAli.setImageResource(R.mipmap.ico_checked);
            }
        });

        binding.btGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (onButtonClick!=null)
                {
                    onButtonClick.onClick(type);
                }
            }
        });


        binding.tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });


    }

    public  void  setMoney(String  money)
    {
        binding.tvPrice.setText("支付金额：¥"+money);
    }

    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width= ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height= ViewGroup.LayoutParams.WRAP_CONTENT;
        layoutParams.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(layoutParams);
    }


    public  interface OnButtonClick{
        void  onClick(int  type);
    }







}
